package com.sup.generator.utils;

import com.mysql.jdbc.util.Base64Decoder;
import com.sup.generator.fixedvalue.GrConst;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.util.Base64Utils;

/**
 * @author Zh
 * @version v1.0
 * @description:
 * @date 2020/11/13 23:18
 */
public class GrBase64Util {

    /**
     * 64编码
     * @param str
     * @return
     */
    public static String base64Coding(String str){
        return Base64Util.encode(str);
    }

    /**
     * 64解码
     * @param redisKey
     * @return
     */
    public static String base64Decoding(String redisKey){
        byte[] deRedisKey = Base64Utils.decodeFromString(redisKey);
        return new String(deRedisKey);
    }


    /**
     * 64加密
     * @param redisKey
     * @return
     */
    public static String base64Encryption(String redisKey){
       return base64Coding(String.format("%s%s",redisKey, GrConst.BASE64_CODE));
    }


    /**
     * 64解密
     * @param redisKey
     * @return
     */
    public static String base64Decryption(String redisKey){
        String str = base64Decoding(redisKey);
        String decryStr = str.substring(0,str.indexOf(GrConst.BRACKETS)+1);
        return decryStr;
    }



    public static void main(String[] args) {
        String endCode = GrBase64Util.base64Coding("12343214321feqfdqfwqfewqr324321534256");
        System.out.println(endCode);
        String reEndCode = GrBase64Util.base64Decoding(endCode);
        System.out.println(reEndCode);
    }

}
